package main

import (
	//"fmt"
	"gorm.io/gorm"
	"gorm.io/driver/mysql"
	"go_part/models"
	"go_part/models/position"
	"go_part/models/robot"
	"go_part/models/fly"
)
  
//   type Product struct {
// 	gorm.Model
// 	Code  string
// 	Price uint
//   }
  
  func main() {
	db, err := gorm.Open(mysql.Open("root:Zanlong123@tcp(127.0.0.1:3306)/ginchat?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{})
	if err != nil {
	  panic("failed to connect database")
	}
  
	// Migrate the schema
	db.AutoMigrate(&models.UserBasic{})
	//db.AutoMigrate(&models.Message{})
	//db.AutoMigrate(&models.Contact{})
	//db.AutoMigrate(&models.GroupBasic{})
	//db.AutoMigrate(&models.Community{})

	// db.AutoMigrate(&models.CompanyBasic{})
	// db.AutoMigrate(&models.DeparkmentBasic{})
	// db.AutoMigrate(&models.LevelType{})
	// db.AutoMigrate(&models.LevelLocal{})
	//db.AutoMigrate(&models.LevelDevice{})

	db.AutoMigrate(&models.ApprovalStepModule{})
	db.AutoMigrate(&models.ApprovalStep{})
	db.AutoMigrate(&models.ApprovalType{})
	db.AutoMigrate(&models.ApprovalLocal{})
	db.AutoMigrate(&models.ApprovalSelfDefine{})

	db.AutoMigrate(&position.PositionDevice{})

	db.AutoMigrate(&rebot.RobotDevice{})
	db.AutoMigrate(&rebot.FunctionBasic{})
	db.AutoMigrate(&rebot.LimitBasic{})

	db.AutoMigrate(&fly.AirportInfo{})
	db.AutoMigrate(&fly.FlyDeviceBasic{})
	db.AutoMigrate(&fly.PositionInfo{})
  
	// Create
	// user := &models.UserBasic{}
	// user.Name = "Zanlong"
	// db.Create(user)
  
	// Read

	// fmt.Println(db.First(user, 1))  // find product with integer primary key
	// //db.First(&product, "code = ?", "D42") // find product with code D42
  
	// // Update - update product's price to 200
	// db.Model(user).Update("PassWord", "1234")
	// Update - update multiple fields
	//db.Model(&product).Updates(Product{Price: 200, Code: "F42"}) // non-zero fields
	//.Model(&product).Updates(map[string]interface{}{"Price": 200, "Code": "F42"})
  
	// Delete - delete product
	//db.Delete(&product, 1)
  }